let app = getApp();
let API_URL = app.globalData.API_URL ;
import { getTutorDetail } from "../../../../request/api.js";
import dayjs from "../../../../common/js/dayjs.js"

Page({

    /**
     * 页面的初始数据
     */
    data: {
        lang: null,
        postId: null,
        teacherInfo: {},
        detailedBoxList: [
            { id: 1, name: 'price', value_ug: 'price', value_zh: 'price' },
            { id: 2, name: 'profession', value_ug: 'profession', value_zh: 'profession' },
            { id: 3, name: 'graduation_time', value_ug: 'graduationTime', value_zh: 'graduationTime' },
            { id: 4, name: 'graduation_campus', value_ug: 'graduatedSchool', value_zh: 'graduatedSchool' },
            { id: 5, name: 'education', value_ug: 'education', value_zh: 'education' }
        ]
    },

    /**
     * My Function
     */
    // 获取内容
    getPost() {
        let postId = this.data.postId
        let data = { postId }
        getTutorDetail(res => {
           if(res.status == 200) {
               let time = res.data
               time.releaseTime = dayjs(time.releaseTime).format("YYYY-MM-DD")
           }
           this.setData({ teacherInfo: res.data })
       }, data);
    },

    // 收藏
    onLike() {
        let user_id = wx.getStorageSync('uid')
        let data = { target_id: parseInt(this.data.postId, 10), user_id, type: 9 }

        wx.request({
            url: `${API_URL}/favorites`,
            data: data,
            method: 'post',
            success: function (res) {
                console.log('res: ', res);
            }
        })
    },

    // 打电话联系
    onContact() {
        wx.makePhoneCall({
            phoneNumber: this.data.teacherInfo.phoneNum,
            fail: cancel => {
                console.log("cancel: ", cancel);
            }
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({ lang: app.globalData.lang, navTitle: "tutorInfo", navigation: true })
        let that = this
        that.setData({ postId: options.itemId })
        this.getPost()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})